﻿//----------------------------------------------------

#region 命名空间

//    版权：
//    作者：
//建立时间：2012-09-11 00:00:33
//    描述：
//----------------------------------------------------
using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using WinnerCMS.Data;
using WinnerCMS.Model;
using WinnerCMS.Common;

#endregion

namespace WinnerCMS.BLL
{
    /// <summary>
    /// 业务逻辑类 WinnerCMS_Favorite 的摘要说明。
    /// </summary>
    public class FavoriteManage
    {
        private static readonly FavoriteDal Dal = new FavoriteDal();

        #region 添加

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Result Add(Favorite model)
        {
            Result res = new Result();
            if (model.Title.Length == 0)
            {
                res.Errors = "“标题”不能为空！";
                return res;
            }
            if (model.Url.Length == 0)
            {
                res.Errors = "“网址”不能为空！";
                return res;
            }
            if (model.Url.ToLower().StartsWith("http") == false)
            {
                model.Url = string.Concat("http://", model.Url);
            }

            if (model.Id == 0)
            {
                Dal.Add(model);
            }
            else
            {
                Dal.Edit(model);
            }
            return res;
        }

        #endregion

        #region 删除

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="UpdatePanel1"></param>
        public void Delete(string ID, UpdatePanel UpdatePanel1)
        {
            if (string.IsNullOrEmpty(ID))
            {
                MsgBox.Message("至少选择一项。", UpdatePanel1);
            }
            else
            {
                Dal.Delete(int.Parse(ID));
            }
        }

        #endregion

        #region 绑定

        /// <summary>
        /// 绑定
        /// </summary>
        /// <param name="pp"></param>
        /// <returns></returns>
        public IList<Favorite> BindList(PagingParam pp)
        {
            return Dal.BindList(UserManage.Current.UserID, pp);
        }

        #endregion
    }
}